local Lua__lanyincr = fk.CreateSkill{
  name = "Lua__lanyincr",
  anim_type = "control",
}

Fk:loadTranslationTable{
  ["Lua__lanyincr"] = "蓝银缠绕",
  ["#Lua__lanyincr"] = "蓝银缠绕：你可以获得其他角色一张牌，然后你将两张牌当作任意一张非伤害多目标锦囊牌使用。",
  [":Lua__lanyincr"] = "出牌阶段限x次，你可以获得其他角色一张牌，然后你将两张牌当作任意一张非伤害多目标锦囊牌使用。你可以令此牌对所有目标失效，改为对其中一个目标结算等量次，每次结算额外令目标①横置②翻面。",
  ["#Lua__lanyincr-card"] = "蓝银缠绕：选择要使用的锦囊牌",
  ["#Lua__lanyincr-target"] = "蓝银缠绕：选择要专注结算的目标",
  ["lanyincr_single"] = "对单一目标结算多次",
  ["lanyincr_multi"] = "对所有目标结算一次",
}

Lua__lanyincr:addEffect("active", {
    anim_type = "control",
    prompt = "#Lua__lanyincr",
    can_use = function(self, player)
        return player:usedSkillTimes(Lua__lanyincr.name, Player.HistoryPhase) <= #player:getTableMark("@Lua__zhahuan")
    end,
    card_num = 0,
    target_num = 1,
    card_filter = Util.FalseFunc,
    target_filter = function(self, player, to_select, selected)
        local target = to_select
        return #selected == 0 and not target:isNude() and to_select ~= player
    end,
    on_use = function(self, room, effect)
        local player = effect.from
        local target = effect.tos[1]
        local hand_cards = target:getCardIds("he")
        local card = hand_cards[math.random(1, #hand_cards)]
        room:obtainCard(player, card, false, fk.ReasonPrey)
        if player:getHandcardNum() > 1 then
            local names = {"amazing_grace","god_salvation","iron_chain"}
            local choice = room:askToChoice(player, {
                choices = names,
                skill_name = Lua__lanyincr.name,
            })
            local use = room:askToUseVirtualCard(player, {
            name = choice,
            skill_name = Lua__lanyincr.name,
            cancelable = false,
            card_filter = {
              n = 2,
              pattern = ".",
            },
            skip = true,
            })
            player.room:useCard(use)
        end
    end,
})

Lua__lanyincr:addEffect(fk.TargetConfirming, {
    anim_type = "defensive",
    can_trigger = function(self, event, target, player, data)
        if not player:hasSkill(Lua__lanyincr.name) then return false end
        return data.from == player and data.card.skillName == Lua__lanyincr.name
    end,
    on_cost = function(self, event, target, player, data)
        local targets = player.room:askToChoosePlayers(player, {
            targets = data.use.tos,
            min_num = 1,
            max_num = 1,
            prompt = "#Lua__lanyincr-target",
            skill_name = Lua__lanyincr.name,
            cancelable = true,
          })
          if #targets > 0 then
            event:setCostData(self, {target = targets[1]})
            return true
          end
    end,
    on_use = function(self, event, target, player, data)
        local room = player.room
        room:setPlayerMark(player, "Lua__lanyincrCS", #data.use.tos)
        for i = #data.use.tos, 1, -1 do
            data:cancelTarget(data.use.tos[i])
        end
        local target = event:getCostData(self).target
        data.use.additionalEffect = (data.use.additionalEffect or 0) + player:getMark("Lua__lanyincrCS") - 1
        data:addTarget(target)
        
        for i = 1, #data.use.tos do
            if not target.chained then
                target:setChainState(true)
            end
            target:turnOver()
        end
    end,
})



return Lua__lanyincr 